<template>
    <view class="page-branch-member page-branch-audit">
        <view class="py-4" v-if="list.length == 0">
            <u-empty text="暂无待审数据" mode="list"></u-empty>
        </view>
        <view class="fly-card">
            <view class="item"  v-for="(item,index) in list" :key="index">
                <!-- <view class="thumb">
                    <u-image :src="proxy.$util.getFullImage(item.avatar)" width="80rpx" height="80rpx" shape="circle"></u-image>
                </view> -->
                <view class="content">
                    <view class="title"><u-icon name="account-fill"/><text class="font-bold ml-2">{{item.nickname}}</text></view>
                    <view class="desc mt-2">
                        <fly-info label="申请时间" :value="item.createTime"></fly-info>
                        <fly-info label="新分会" :value="item.newGuildName"></fly-info>
                        <fly-info label="原公会" :value="item.guildName"></fly-info>
                        <fly-info label="备注" :value="item.remark"></fly-info>
                        <fly-info label="状态">
                            <text :class="'status-' + item.status">{{ proxy.$util.setName(item.status, optionData.changeStatus) }}</text>
                        </fly-info>
                    </view>
                    <view class="float-right" v-if="item.status == 0">
                        <u-button class="btn-cyan" size="mini" @click="handlePass(item)">同意</u-button>
                        <text class="mr-2"></text>
                        <u-button class="btn-red" size="mini" @click="handleRefund(item)">拒绝</u-button>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>
<script setup lang="ts">
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
import FlyInfo from '@/components/FlyInfo/index';
import {onShow, onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import { useAppStore } from '@/stores/app';
import { useOptionData } from '@/stores/optionData';
let appStore = useAppStore();
const optionDataStore = useOptionData();
let list = ref([]);
let optionData = reactive({});
const getInitData = async () => {
    optionData.changeStatus = await optionDataStore.getDictList('change_status');
}
const getList = () => {
    proxy.$http('get', '/admin/userNewGuilds/newGuildsList', {status: 0}, (data,msg) => {
        list.value = data;
    })
};
const handlePass = (item) => {
    uni.showModal({
        title: '确定同意转会？',
        success: res => {
            if(res.confirm){
                let params = {
					id: item.id,
					status: 1,
					comment: null,
				};
                submitForm(params);
            }
        }
    })
}
const handleRefund = (item) => {
	uni.showModal({
		title: '确定要拒绝吗？',
		editable: true,
		placeholderText: '请输入备注',
		success: res => {
			if(res.confirm){
				let params = {
					id: item.id,
					status: 2,
					comment: res.content
				};
                submitForm(params);
				
			}
		}
	})
};
const submitForm = (params) => {
    proxy.$http('post', '/admin/userNewGuilds/updateUserNewGuilds', params, (data,msg) => {
		uni.showToast({title: '提交成功', icon: 'none'});
		getList('refresh');
	})
}
onPullDownRefresh(() => {
	getList();
	setTimeout( () => {
		uni.stopPullDownRefresh();
	}, 1000);
});
onReachBottom(() =>{
	getList();
});
onShow(() => {    
    getInitData();
	getList('refresh');
})
</script>